<template>
  <el-card>
    <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
    <div ref="main" style="width: 100%;height:500px;"></div>
  </el-card>
</template>

<script>
import * as echarts from 'echarts'
export default {
  props: {
    option: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {}
  },

  mounted() {
    this.showEcherts()
  },

  methods: {
    showEcherts() {
      console.log(this.option)
      var myChart = echarts.init(this.$refs.main)
      var option = {
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: Object.keys(this.option).reverse()
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: Object.values(this.option).reverse(),
            type: 'line',
            areaStyle: {}
          }
        ]
      }
      myChart.setOption(option)
    }
  },
  watch: {
    option: {
      handler() {
        this.showEcherts()
      },
      deep: true
    }
  }
}
</script>

<style lang="less" scoped></style>
